def Prime(number):
  el = 0
  newList = []
  if number // 1000 < 10 and number // 1000 >= 1:
      # перевод из списков чисел в числа
      for element in listExpect:
          nI = int("".join(map(str, element)))
          newList.append(nI)
      newList.sort()
      newList.reverse()
      # проверка на четность
      for i in newList:
          count = 0
          for x in range(2, i-1):
              if i % x == 0:
                  count += 1
          if count == 0 and i != 1:
              el += 1
              return i
              break
      if el == 0:
         return 0
  else:
      return  0


number = int(input())
listOfNum = list(map(int, str(number)))
listExpect = []
start = 0
n = 0
end = 1
# нахождение всех комбинаций чисел из number
for i in listOfNum:
   ind = listOfNum.index(i)
   while n < len(listOfNum) - ind:
       listExpect.append(listOfNum[start:end])
       end += 1
       n += 1
   start = ind + 1
   end = start + 1
   n = 0
print(Prime(number))